<!--
 * @Author: weikang
 * @Description:
 * @Date: 2024-01-07 15:15:34
 * @LastEditTime: 2024-01-07 15:16:47
 * @FilePath: \env-manager-pc\src\views\document\device\status.edit.vue
-->
<script setup lang="ts">
import type { FormInstance } from 'element-plus'
import { useInitForm } from './page'
import { ModelType } from '@/types/common'
import type { ModelOpen } from '@/types/page'

const emits = defineEmits(['submit'])
const dialogVisible = ref(false)
const { formData, initForm } = useInitForm()
const formRef = ref<FormInstance>()
const btnLoading = ref(false)
const modelType = ref(ModelType.add)
function handleClose() {
  close()
}

function open(options: ModelOpen) {
  modelType.value = options.type
  if (options.data) {
    formData.value = { ...options.data }
  }
  dialogVisible.value = true
}

function doLoading(flag: boolean) {
  btnLoading.value = flag
}

function submit() {
  emits('submit', formData.value, doLoading)
}

function close() {
  dialogVisible.value = false
  btnLoading.value = false
  initForm()
}

defineExpose({
  open,
  close,
})
</script>

<template>
  <el-dialog
    v-model="dialogVisible"
    append-to-body
    title="状态维护"
    width="30%"
    :before-close="handleClose"
  >
    <ElForm ref="formRef" label-width="180px" label-position="top" label-suffix="：">
      <ElRow :gutter="30">
        <ElCol :span="12">
          <ElFormItem label="状态变更" prop="Name">
            <ElInput v-model="formData.status" />
          </ElFormItem>
        </ElCol>
        <ElCol :span="12">
          <ElFormItem label="备注" prop="Location">
            <ElInput v-model="formData.mark" />
          </ElFormItem>
        </ElCol>
      </ElRow>
    </ElForm>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" :loading="btnLoading" @click="submit">
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
